/*
 * luart.c
 *
 * Created: 7/27/2012 12:53:42 PM
 *  Author: we
 */ 

#include <avr/io.h>

#include "luart.h"

void usart_init(void)
{
	// USART initialization
	// Communication Parameters: 8 Data, 1 Stop, No Parity
	// USART Receiver: On
	// USART Transmitter: On
	// USART Mode: Asynchronous
	// USART Baud Rate: 4800
	UCSRA=0x00;
	UCSRB=0x98;
	UCSRC=0x86;
	UBRRH=0x00;
	UBRRL=0x0C;
}

void usart_transmit_int(unsigned char data)
{
	while ( !(UCSRA & (1 << UDRE)) );
	UDR = data;
}

void usart_transmit_symbol(char data)
{
	while ( !(UCSRA & (1 << UDRE)) );
	UDR = data;
}

void usart_print(char data[])
{
	// print string
	for (int i = 0; data[i] != '\0'; i++)
	{
		usart_transmit_symbol(data[i]);
	}		
}

void usart_newline()
{
	usart_transmit_symbol(UART_NEWLINE);
	usart_transmit_symbol(UART_CRETURN);
}

void usart_println(char data[])
{
	usart_print(data);
	usart_newline();
}
